package cn.buddha.jesa.conditional.base.config;

import cn.buddha.jesa.conditional.base.LinuxCondition;
import cn.buddha.jesa.conditional.base.WinCondition;
import cn.buddha.jesa.conditional.base.model.ConditionModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;

/**
 * @ClassName ConditionalBaseConf
 * @Author 友野浩二
 * @Version 1.0
 */
@Configuration
@Slf4j
public class ConditionalBaseConf {

    // @Conditional是Spring4新提供的注解，它的作用是按照一定的条件进行判断，满足条件给容器注册bean。
    @Conditional({WinCondition.class})
    @Bean(name = "win")
    public ConditionModel model1() {
        log.info("ConditionBeanConf 注入 Windows 实体");
        return ConditionModel.builder().osName("Windows 系统").osCode("001").build();
    }

    @Conditional(LinuxCondition.class)
    @Bean(name = "linux")
    public ConditionModel model2() {
        log.info("ConditionBeanConf 注入 Linux 实体");
        return ConditionModel.builder().osName("Linux 系统").osCode("002").build();
    }

}
